package com.eee.machine.controller;

import com.eee.machine.common.OperateResponse;
import com.eee.machine.common.TableData;
import com.eee.machine.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/product")
@Controller
public class ProductController {

    @Autowired
    private IProductService productService;

    @RequestMapping("/getAllProduct")
    @ResponseBody
    TableData getAllProduct(@RequestParam(value = "page") String page, @RequestParam(value = "limit") String limit){
        return productService.getAllProduct(Long.parseLong(page), Long.parseLong(limit));
    }

    @RequestMapping("/deliverGood")
    String deliverGood(ModelMap map, String itemId){
        map.addAttribute("itemId", itemId);
        return "machine/deliverMachine";
    }

    @RequestMapping("/checkGood")
    @ResponseBody
    OperateResponse checkGood(String itemId, String machineId){
        return productService.checkGood(itemId, machineId);
    }
}
